%matplotlib inline
import os
host = os.environ['CASHOST']
port = os.environ['CASPORT']
userid = None
password = None
# needed to start a CAS server.
from swat import *
sess = CAS(host, port,userid, password)
from dlpy.images import ImageTable
my_images = ImageTable.load_files(sess, path='/dept/cas/leliuz/Data/Demo/Giraffe_Dolphin')
my_images.head()
| _image_ | _label_ | _filename_0 | |
|---|---|---|---|
| 0 | b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x01... | Dolphin | dolphin_10158.jpg |
| 1 | b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x01... | Dolphin | dolphin_10920.jpg |
| 2 | b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x01... | Dolphin | dolphin_10924.jpg |
| 3 | b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x01... | Dolphin | dolphin_10213.jpg |
| 4 | b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x01... | Dolphin | dolphin_10937.jpg |
my_images.columninfo()
| Column | ID | Type | RawLength | FormattedLength | NFL | NFD | |
|---|---|---|---|---|---|---|---|
| 0 | _image_ | 1 | varbinary | 1075587 | 1075587 | 0 | 0 |
| 1 | _label_ | 2 | varchar | 7 | 7 | 0 | 0 |
| 2 | _filename_0 | 3 | varchar | 17 | 17 | 0 | 0 |
elapsed 0.0105s · user 0.00921s · sys 0.0159s · mem 2.93MB
my_images.show(nimages=8,ncol=4, randomize=True)
my_images.label_freq
| Level | Frequency | |
|---|---|---|
| Dolphin | 1 | 237 |
| Giraffe | 2 | 172 |
my_images.image_summary
jpg 409 minWidth 170 maxWidth 1024 minHeight 127 maxHeight 1024 meanWidth 912.147 meanHeight 778.499 mean1stChannel 128.718 min1stChannel 0 max1stChannel 255 mean2ndChannel 124.123 min2ndChannel 0 max2ndChannel 255 mean3rdChannel 94.2449 min3rdChannel 0 max3rdChannel 255 dtype: object
my_images.resize(width=224)
my_images.show(8,4)
from dlpy.splitting import two_way_split
tr_img, te_img = two_way_split(my_images,test_rate=20, seed = 123)
tr_img.label_freq
| Level | Frequency | |
|---|---|---|
| Dolphin | 1 | 190 |
| Giraffe | 2 | 138 |
te_img.label_freq
| Level | Frequency | |
|---|---|---|
| Dolphin | 1 | 47 |
| Giraffe | 2 | 34 |
tr_img.as_patches(width=200,height=200,step_size=24,output_width=224,output_height=224)
tr_img.label_freq
| Level | Frequency | |
|---|---|---|
| Dolphin | 1 | 760 |
| Giraffe | 2 | 552 |
tr_img.show(8,4)
from dlpy import Model, Sequential
from dlpy.layers import *
from dlpy.applications import *
model1 = Sequential(sess, model_name = 'Simple_CNN')
Input Layer
model1.add(InputLayer(3,224,224,offsets=tr_img.channel_means))
NOTE: Input layer added.
1 Convolution 1 Pooling
model1.add(Conv2d(8,7))
model1.add(Pooling(2))
NOTE: Convolutional layer added. NOTE: Pooling layer added.
1 Convolution 1 Pooling
model1.add(Conv2d(8,7))
model1.add(Pooling(2))
NOTE: Convolutional layer added. NOTE: Pooling layer added.
1 Dense layer
model1.add(Dense(16))
NOTE: Fully-connected layer added.
Output layer
model1.add(OutputLayer(act='softmax',n=2))
NOTE: Output layer added. NOTE: Model compiled successfully.
model1.print_summary()
*==================*===============*========*============*=================*======================* | Layer (Type) | Kernel Size | Stride | Activation | Output Size | Number of Parameters | *------------------*---------------*--------*------------*-----------------*----------------------* | Data(Input) | None | None | None | (224, 224, 3) | 0 / 0 | | Conv1_1(Convo.) | (7, 7) | 1 | Relu | (224, 224, 8) | 1176 / 8 | | Pool1(Pool) | (2, 2) | 2 | Max | (112, 112, 8) | 0 / 0 | | Conv2_1(Convo.) | (7, 7) | 1 | Relu | (112, 112, 8) | 3136 / 8 | | Pool2(Pool) | (2, 2) | 2 | Max | (56, 56, 8) | 0 / 0 | | FC1(F.C.) | (25088, 16) | None | Relu | 16 | 401408 / 16 | | Output(Output) | (16, 2) | None | Softmax | 2 | 32 / 2 | *==================*===============*========*============*=================*======================* |Total Number of Parameters: 405,786 | *=================================================================================================*
# You need install graphviz to run this, otherwise, just skip this line.
model1.plot_network()
model1.fit(data=tr_img, mini_batch_size=2, max_epochs=3, lr=1E-4)
NOTE: Training from scratch. NOTE: The Synchronous mode is enabled. NOTE: The total number of parameters is 405786. NOTE: The approximate memory cost is 1425.00 MB. NOTE: Loading weights cost 0.00 (s). NOTE: Initializing each layer cost 0.76 (s). NOTE: The total number of workers is 7. NOTE: The total number of threads on each worker is 32. NOTE: The total minibatch size per thread on each worker is 2. NOTE: The maximum minibatch size across all workers for the synchronous mode is 448. NOTE: Target variable: _label_ NOTE: Number of levels for the target variable: 2 NOTE: Levels for the target variable: NOTE: Level 0: Dolphin NOTE: Level 1: Giraffe NOTE: Number of input variables: 1 NOTE: Number of numeric input variables: 1 NOTE: Batch nUsed Learning Rate Loss Fit Error Time (s) (Training) NOTE: 0 448 0.0001 10.817 0.5915 0.03 NOTE: 1 448 0.0001 9.5084 0.4129 0.02 NOTE: 2 382 0.0001 0.607 0.3246 0.02 NOTE: 3 34 0.0001 0.6833 0.4118 0.02 NOTE: Epoch Learning Rate Loss Fit Error Time (s) NOTE: 0 0.0001 7.1347 0.4482 2.16 NOTE: Batch nUsed Learning Rate Loss Fit Error Time (s) (Training) NOTE: 0 448 0.0001 0.6425 0.2835 0.05 NOTE: 1 448 0.0001 0.6014 0.2455 0.02 NOTE: 2 382 0.0001 0.557 0.2644 0.05 NOTE: 3 34 0.0001 0.6045 0.3529 0.02 NOTE: 1 0.0001 0.6026 0.2668 2.18 NOTE: Batch nUsed Learning Rate Loss Fit Error Time (s) (Training) NOTE: 0 448 0.0001 0.601 0.25 0.03 NOTE: 1 448 0.0001 0.5644 0.2143 0.04 NOTE: 2 382 0.0001 0.5289 0.2356 0.04 NOTE: 3 34 0.0001 0.5717 0.3235 0.06 NOTE: 2 0.0001 0.5667 0.2355 2.88 NOTE: The optimization reached the maximum number of epochs. NOTE: The total time is 7.22 (s).
| Descr | Value | |
|---|---|---|
| 0 | Model Name | simple_cnn |
| 1 | Model Type | Convolutional Neural Network |
| 2 | Number of Layers | 7 |
| 3 | Number of Input Layers | 1 |
| 4 | Number of Output Layers | 1 |
| 5 | Number of Convolutional Layers | 2 |
| 6 | Number of Pooling Layers | 2 |
| 7 | Number of Fully Connected Layers | 1 |
| 8 | Number of Weight Parameters | 405752 |
| 9 | Number of Bias Parameters | 34 |
| 10 | Total Number of Model Parameters | 405786 |
| 11 | Approximate Memory Cost for Training (MB) | 1425 |
| Epoch | LearningRate | Loss | FitError | |
|---|---|---|---|---|
| 0 | 1 | 0.0001 | 7.134707 | 0.448171 |
| 1 | 2 | 0.0001 | 0.602615 | 0.266768 |
| 2 | 3 | 0.0001 | 0.566738 | 0.235518 |
| casLib | Name | Rows | Columns | casTable | |
|---|---|---|---|---|---|
| 0 | CASUSERHDFS(leliuz) | Simple_CNN_weights | 405786 | 3 | CASTable('Simple_CNN_weights', caslib='CASUSER... |
elapsed 8.29s · user 727s · sys 25.9s · mem 1.04e+04MB
model1.fit(data=tr_img, mini_batch_size=3, max_epochs=3, lr=5E-5, log_level=3)
NOTE: Training based on existing weights. NOTE: The Synchronous mode is enabled. NOTE: The total number of parameters is 405786. NOTE: The approximate memory cost is 1612.00 MB. NOTE: Loading weights cost 0.03 (s). NOTE: Initializing each layer cost 0.52 (s). NOTE: The total number of workers is 7. NOTE: The total number of threads on each worker is 32. NOTE: The total minibatch size per thread on each worker is 3. NOTE: The maximum minibatch size across all workers for the synchronous mode is 672. NOTE: Target variable: _label_ NOTE: Number of levels for the target variable: 2 NOTE: Levels for the target variable: NOTE: Level 0: Dolphin NOTE: Level 1: Giraffe NOTE: Number of input variables: 1 NOTE: Number of numeric input variables: 1 NOTE: Batch nUsed Learning Rate Loss Fit Error Time (s) (Training) NOTE: 0 672 5E-5 0.5717 0.2158 0.06 NOTE: 1 606 5E-5 0.5148 0.2195 0.07 NOTE: 2 34 5E-5 0.5509 0.2647 0.03 NOTE: Epoch Learning Rate Loss Fit Error Time (s) NOTE: 0 5E-5 0.5449 0.2188 2.44 NOTE: Batch nUsed Learning Rate Loss Fit Error Time (s) (Training) NOTE: 0 672 5E-5 0.5633 0.2098 0.02 NOTE: 1 606 5E-5 0.5063 0.2162 0.02 NOTE: 2 34 5E-5 0.5408 0.2941 0.03 NOTE: 1 5E-5 0.5364 0.2149 2.02 NOTE: Batch nUsed Learning Rate Loss Fit Error Time (s) (Training) NOTE: 0 672 5E-5 0.5559 0.2054 0.02 NOTE: 1 606 5E-5 0.499 0.2079 0.04 NOTE: 2 34 5E-5 0.5312 0.2941 0.03 NOTE: 2 5E-5 0.529 0.2088 1.91 NOTE: The optimization reached the maximum number of epochs. NOTE: The total time is 6.37 (s).
| Descr | Value | |
|---|---|---|
| 0 | Model Name | simple_cnn |
| 1 | Model Type | Convolutional Neural Network |
| 2 | Number of Layers | 7 |
| 3 | Number of Input Layers | 1 |
| 4 | Number of Output Layers | 1 |
| 5 | Number of Convolutional Layers | 2 |
| 6 | Number of Pooling Layers | 2 |
| 7 | Number of Fully Connected Layers | 1 |
| 8 | Number of Weight Parameters | 405752 |
| 9 | Number of Bias Parameters | 34 |
| 10 | Total Number of Model Parameters | 405786 |
| 11 | Approximate Memory Cost for Training (MB) | 1612 |
| Epoch | LearningRate | Loss | FitError | |
|---|---|---|---|---|
| 0 | 4 | 0.00005 | 0.544852 | 0.218750 |
| 1 | 5 | 0.00005 | 0.536396 | 0.214939 |
| 2 | 6 | 0.00005 | 0.528979 | 0.208841 |
| casLib | Name | Rows | Columns | casTable | |
|---|---|---|---|---|---|
| 0 | CASUSERHDFS(leliuz) | Simple_CNN_weights | 405786 | 3 | CASTable('Simple_CNN_weights', caslib='CASUSER... |
elapsed 7.25s · user 767s · sys 21.8s · mem 1.17e+04MB
model1.training_history
| Epoch | LearningRate | Loss | FitError | |
|---|---|---|---|---|
| 0 | 1 | 0.00010 | 7.134707 | 0.448171 |
| 1 | 2 | 0.00010 | 0.602615 | 0.266768 |
| 2 | 3 | 0.00010 | 0.566738 | 0.235518 |
| 3 | 4 | 0.00005 | 0.544852 | 0.218750 |
| 4 | 5 | 0.00005 | 0.536396 | 0.214939 |
| 5 | 6 | 0.00005 | 0.528979 | 0.208841 |
model1.plot_training_history(fig_size=(10,4))
model1.predict(te_img)
| Descr | Value | |
|---|---|---|
| 0 | Number of Observations Read | 81 |
| 1 | Number of Observations Used | 81 |
| 2 | Misclassification Error (%) | 20.98765 |
| 3 | Loss Error | 0.546549 |
| casLib | Name | Rows | Columns | casTable | |
|---|---|---|---|---|---|
| 0 | CASUSERHDFS(leliuz) | Valid_Res_Sj2beY | 81 | 8 | CASTable('Valid_Res_Sj2beY', caslib='CASUSERHD... |
elapsed 0.704s · user 5.46s · sys 3.63s · mem 8.9e+03MB
model1.valid_conf_mat
| _label_ | Col1 | Col2 | |
|---|---|---|---|
| 0 | Dolphin | 36.0 | 11.0 |
| 1 | Giraffe | 6.0 | 28.0 |
elapsed 0.04s · user 0.0595s · sys 0.0714s · mem 13.1MB
model1.plot_predict_res(type='C',image_id=2)
model1.plot_predict_res(type='M',image_id=0)
model1.heat_map_analysis(data=te_img, mask_width=56, mask_height=56, step_size=8)
NOTE : The number of images in the table is too large, only 5 randomly selected images are used in analysis. NOTE: Table IMAGEDATA_KETQS0 contains compressed images.
| _filename_0 | _image_ | _label_ | heat_map | |
|---|---|---|---|---|
| 0 | giraffe_11069.jpg | <PIL.JpegImagePlugin.JpegImageFile image mode=... | Giraffe | [[0.5000260472297668, 0.5000260472297668, 0.50... |
| 1 | giraffe_10831.jpg | <PIL.JpegImagePlugin.JpegImageFile image mode=... | Giraffe | [[0.5000260472297668, 0.5000260472297668, 0.50... |
| 2 | dolphin_10937.jpg | <PIL.JpegImagePlugin.JpegImageFile image mode=... | Dolphin | [[0.7850251197814941, 0.7850251197814941, 0.78... |
| 3 | dolphin_10368.jpg | <PIL.JpegImagePlugin.JpegImageFile image mode=... | Dolphin | [[0.9709257483482361, 0.9709257483482361, 0.97... |
| 4 | dolphin_10811.jpg | <PIL.JpegImagePlugin.JpegImageFile image mode=... | Dolphin | [[0.49997398257255554, 0.49997398257255554, 0.... |
model1.get_feature_maps(data=te_img,label='Dolphin', image_id=0)
model1.feature_maps.display(layer_id=0)
model1.feature_maps.display(layer_id=1)
model1.feature_maps.display(layer_id=2)
model1.deploy(path='/dept/cas/leliuz/Data/Demo/', output_format='astore')
NOTE: Model astore file saved successfully.
model1.deploy(path='/dept/cas/leliuz/Data/Demo/', output_format='table')
NOTE: Model table saved successfully.
from dlpy.applications import ResNet50_Caffe, VGG16
model2 = ResNet50_Caffe(sess, model_name='RESNET50_CAFFE', batch_norm_first=False,
n_classes=1000, n_channels=3, width=224, height=224, scale=1,
random_flip='none', random_crop='none',
offsets=(103.939, 116.779, 123.68),
pre_train_weight=True, include_top=True)
NOTE: Model table is attached successfully! NOTE: Model is named to "resnet50_caffe" according to the model name in the table. NOTE: Cloud Analytic Services made the uploaded file available as table LABEL_ZKN3CO in caslib CASUSERHDFS(leliuz). NOTE: The table LABEL_ZKN3CO has been created in caslib CASUSERHDFS(leliuz) from binary data uploaded to Cloud Analytic Services.
model2.print_summary()
*==================*===============*========*============*=================*======================* | Layer (Type) | Kernel Size | Stride | Activation | Output Size | Number of Parameters | *------------------*---------------*--------*------------*-----------------*----------------------* | data(Input) | None | None | None | (224, 224, 3) | 0 / 0 | | conv1(Convo.) | (7, 7) | 2 | Identity | (112, 112, 64) | 9408 / 64 | | bn_conv1(B.N.) | None | None | Rectifier | (112, 112, 64) | 0 / 128 | | pool1(Pool) | (3, 3) | 2 | Max | (56, 56, 64) | 0 / 0 | | res2a_branch2a...| (1, 1) | 1 | Identity | (56, 56, 64) | 4096 / 0 | | bn2a_branch2a(...| None | None | Rectifier | (56, 56, 64) | 0 / 128 | | res2a_branch2b...| (3, 3) | 1 | Identity | (56, 56, 64) | 36864 / 0 | | bn2a_branch2b(...| None | None | Rectifier | (56, 56, 64) | 0 / 128 | | res2a_branch2c...| (1, 1) | 1 | Identity | (56, 56, 256) | 16384 / 0 | | bn2a_branch2c(...| None | None | Identity | (56, 56, 256) | 0 / 512 | | res2a_branch1(...| (1, 1) | 1 | Identity | (56, 56, 256) | 16384 / 0 | | bn2a_branch1(B...| None | None | Identity | (56, 56, 256) | 0 / 512 | | res2a(Resid.) | None | None | Rectifier | (56, 56, 256) | 0 / 0 | | res2b_branch2a...| (1, 1) | 1 | Identity | (56, 56, 64) | 16384 / 0 | | bn2b_branch2a(...| None | None | Rectifier | (56, 56, 64) | 0 / 128 | | res2b_branch2b...| (3, 3) | 1 | Identity | (56, 56, 64) | 36864 / 0 | | bn2b_branch2b(...| None | None | Rectifier | (56, 56, 64) | 0 / 128 | | res2b_branch2c...| (1, 1) | 1 | Identity | (56, 56, 256) | 16384 / 0 | | bn2b_branch2c(...| None | None | Identity | (56, 56, 256) | 0 / 512 | | res2b(Resid.) | None | None | Rectifier | (56, 56, 256) | 0 / 0 | | res2c_branch2a...| (1, 1) | 1 | Identity | (56, 56, 64) | 16384 / 0 | | bn2c_branch2a(...| None | None | Rectifier | (56, 56, 64) | 0 / 128 | | res2c_branch2b...| (3, 3) | 1 | Identity | (56, 56, 64) | 36864 / 0 | | bn2c_branch2b(...| None | None | Rectifier | (56, 56, 64) | 0 / 128 | | res2c_branch2c...| (1, 1) | 1 | Identity | (56, 56, 256) | 16384 / 0 | | bn2c_branch2c(...| None | None | Identity | (56, 56, 256) | 0 / 512 | | res2c(Resid.) | None | None | Rectifier | (56, 56, 256) | 0 / 0 | | res3a_branch2a...| (1, 1) | 2 | Identity | (28, 28, 128) | 32768 / 0 | | bn3a_branch2a(...| None | None | Rectifier | (28, 28, 128) | 0 / 256 | | res3a_branch2b...| (3, 3) | 1 | Identity | (28, 28, 128) | 147456 / 0 | | bn3a_branch2b(...| None | None | Rectifier | (28, 28, 128) | 0 / 256 | | res3a_branch2c...| (1, 1) | 1 | Identity | (28, 28, 512) | 65536 / 0 | | bn3a_branch2c(...| None | None | Identity | (28, 28, 512) | 0 / 1024 | | res3a_branch1(...| (1, 1) | 2 | Identity | (28, 28, 512) | 131072 / 0 | | bn3a_branch1(B...| None | None | Identity | (28, 28, 512) | 0 / 1024 | | res3a(Resid.) | None | None | Rectifier | (28, 28, 512) | 0 / 0 | | res3b_branch2a...| (1, 1) | 1 | Identity | (28, 28, 128) | 65536 / 0 | | bn3b_branch2a(...| None | None | Rectifier | (28, 28, 128) | 0 / 256 | | res3b_branch2b...| (3, 3) | 1 | Identity | (28, 28, 128) | 147456 / 0 | | bn3b_branch2b(...| None | None | Rectifier | (28, 28, 128) | 0 / 256 | | res3b_branch2c...| (1, 1) | 1 | Identity | (28, 28, 512) | 65536 / 0 | | bn3b_branch2c(...| None | None | Identity | (28, 28, 512) | 0 / 1024 | | res3b(Resid.) | None | None | Rectifier | (28, 28, 512) | 0 / 0 | | res3c_branch2a...| (1, 1) | 1 | Identity | (28, 28, 128) | 65536 / 0 | | bn3c_branch2a(...| None | None | Rectifier | (28, 28, 128) | 0 / 256 | | res3c_branch2b...| (3, 3) | 1 | Identity | (28, 28, 128) | 147456 / 0 | | bn3c_branch2b(...| None | None | Rectifier | (28, 28, 128) | 0 / 256 | | res3c_branch2c...| (1, 1) | 1 | Identity | (28, 28, 512) | 65536 / 0 | | bn3c_branch2c(...| None | None | Identity | (28, 28, 512) | 0 / 1024 | | res3c(Resid.) | None | None | Rectifier | (28, 28, 512) | 0 / 0 | | res3d_branch2a...| (1, 1) | 1 | Identity | (28, 28, 128) | 65536 / 0 | | bn3d_branch2a(...| None | None | Rectifier | (28, 28, 128) | 0 / 256 | | res3d_branch2b...| (3, 3) | 1 | Identity | (28, 28, 128) | 147456 / 0 | | bn3d_branch2b(...| None | None | Rectifier | (28, 28, 128) | 0 / 256 | | res3d_branch2c...| (1, 1) | 1 | Identity | (28, 28, 512) | 65536 / 0 | | bn3d_branch2c(...| None | None | Identity | (28, 28, 512) | 0 / 1024 | | res3d(Resid.) | None | None | Rectifier | (28, 28, 512) | 0 / 0 | | res4a_branch2a...| (1, 1) | 2 | Identity | (14, 14, 256) | 131072 / 0 | | bn4a_branch2a(...| None | None | Rectifier | (14, 14, 256) | 0 / 512 | | res4a_branch2b...| (3, 3) | 1 | Identity | (14, 14, 256) | 589824 / 0 | | bn4a_branch2b(...| None | None | Rectifier | (14, 14, 256) | 0 / 512 | | res4a_branch2c...| (1, 1) | 1 | Identity | (14, 14, 1024) | 262144 / 0 | | bn4a_branch2c(...| None | None | Identity | (14, 14, 1024) | 0 / 2048 | | res4a_branch1(...| (1, 1) | 2 | Identity | (14, 14, 1024) | 524288 / 0 | | bn4a_branch1(B...| None | None | Identity | (14, 14, 1024) | 0 / 2048 | | res4a(Resid.) | None | None | Rectifier | (14, 14, 1024) | 0 / 0 | | res4b_branch2a...| (1, 1) | 1 | Identity | (14, 14, 256) | 262144 / 0 | | bn4b_branch2a(...| None | None | Rectifier | (14, 14, 256) | 0 / 512 | | res4b_branch2b...| (3, 3) | 1 | Identity | (14, 14, 256) | 589824 / 0 | | bn4b_branch2b(...| None | None | Rectifier | (14, 14, 256) | 0 / 512 | | res4b_branch2c...| (1, 1) | 1 | Identity | (14, 14, 1024) | 262144 / 0 | | bn4b_branch2c(...| None | None | Identity | (14, 14, 1024) | 0 / 2048 | | res4b(Resid.) | None | None | Rectifier | (14, 14, 1024) | 0 / 0 | | res4c_branch2a...| (1, 1) | 1 | Identity | (14, 14, 256) | 262144 / 0 | | bn4c_branch2a(...| None | None | Rectifier | (14, 14, 256) | 0 / 512 | | res4c_branch2b...| (3, 3) | 1 | Identity | (14, 14, 256) | 589824 / 0 | | bn4c_branch2b(...| None | None | Rectifier | (14, 14, 256) | 0 / 512 | | res4c_branch2c...| (1, 1) | 1 | Identity | (14, 14, 1024) | 262144 / 0 | | bn4c_branch2c(...| None | None | Identity | (14, 14, 1024) | 0 / 2048 | | res4c(Resid.) | None | None | Rectifier | (14, 14, 1024) | 0 / 0 | | res4d_branch2a...| (1, 1) | 1 | Identity | (14, 14, 256) | 262144 / 0 | | bn4d_branch2a(...| None | None | Rectifier | (14, 14, 256) | 0 / 512 | | res4d_branch2b...| (3, 3) | 1 | Identity | (14, 14, 256) | 589824 / 0 | | bn4d_branch2b(...| None | None | Rectifier | (14, 14, 256) | 0 / 512 | | res4d_branch2c...| (1, 1) | 1 | Identity | (14, 14, 1024) | 262144 / 0 | | bn4d_branch2c(...| None | None | Identity | (14, 14, 1024) | 0 / 2048 | | res4d(Resid.) | None | None | Rectifier | (14, 14, 1024) | 0 / 0 | | res4e_branch2a...| (1, 1) | 1 | Identity | (14, 14, 256) | 262144 / 0 | | bn4e_branch2a(...| None | None | Rectifier | (14, 14, 256) | 0 / 512 | | res4e_branch2b...| (3, 3) | 1 | Identity | (14, 14, 256) | 589824 / 0 | | bn4e_branch2b(...| None | None | Rectifier | (14, 14, 256) | 0 / 512 | | res4e_branch2c...| (1, 1) | 1 | Identity | (14, 14, 1024) | 262144 / 0 | | bn4e_branch2c(...| None | None | Identity | (14, 14, 1024) | 0 / 2048 | | res4e(Resid.) | None | None | Rectifier | (14, 14, 1024) | 0 / 0 | | res4f_branch2a...| (1, 1) | 1 | Identity | (14, 14, 256) | 262144 / 0 | | bn4f_branch2a(...| None | None | Rectifier | (14, 14, 256) | 0 / 512 | | res4f_branch2b...| (3, 3) | 1 | Identity | (14, 14, 256) | 589824 / 0 | | bn4f_branch2b(...| None | None | Rectifier | (14, 14, 256) | 0 / 512 | | res4f_branch2c...| (1, 1) | 1 | Identity | (14, 14, 1024) | 262144 / 0 | | bn4f_branch2c(...| None | None | Identity | (14, 14, 1024) | 0 / 2048 | | res4f(Resid.) | None | None | Rectifier | (14, 14, 1024) | 0 / 0 | | res5a_branch2a...| (1, 1) | 2 | Identity | (7, 7, 512) | 524288 / 0 | | bn5a_branch2a(...| None | None | Rectifier | (7, 7, 512) | 0 / 1024 | | res5a_branch2b...| (3, 3) | 1 | Identity | (7, 7, 512) | 2359296 / 0 | | bn5a_branch2b(...| None | None | Rectifier | (7, 7, 512) | 0 / 1024 | | res5a_branch2c...| (1, 1) | 1 | Identity | (7, 7, 2048) | 1048576 / 0 | | bn5a_branch2c(...| None | None | Identity | (7, 7, 2048) | 0 / 4096 | | res5a_branch1(...| (1, 1) | 2 | Identity | (7, 7, 2048) | 2097152 / 0 | | bn5a_branch1(B...| None | None | Identity | (7, 7, 2048) | 0 / 4096 | | res5a(Resid.) | None | None | Rectifier | (7, 7, 2048) | 0 / 0 | | res5b_branch2a...| (1, 1) | 1 | Identity | (7, 7, 512) | 1048576 / 0 | | bn5b_branch2a(...| None | None | Rectifier | (7, 7, 512) | 0 / 1024 | | res5b_branch2b...| (3, 3) | 1 | Identity | (7, 7, 512) | 2359296 / 0 | | bn5b_branch2b(...| None | None | Rectifier | (7, 7, 512) | 0 / 1024 | | res5b_branch2c...| (1, 1) | 1 | Identity | (7, 7, 2048) | 1048576 / 0 | | bn5b_branch2c(...| None | None | Identity | (7, 7, 2048) | 0 / 4096 | | res5b(Resid.) | None | None | Rectifier | (7, 7, 2048) | 0 / 0 | | res5c_branch2a...| (1, 1) | 1 | Identity | (7, 7, 512) | 1048576 / 0 | | bn5c_branch2a(...| None | None | Rectifier | (7, 7, 512) | 0 / 1024 | | res5c_branch2b...| (3, 3) | 1 | Identity | (7, 7, 512) | 2359296 / 0 | | bn5c_branch2b(...| None | None | Rectifier | (7, 7, 512) | 0 / 1024 | | res5c_branch2c...| (1, 1) | 1 | Identity | (7, 7, 2048) | 1048576 / 0 | | bn5c_branch2c(...| None | None | Identity | (7, 7, 2048) | 0 / 4096 | | res5c(Resid.) | None | None | Rectifier | (7, 7, 2048) | 0 / 0 | | pool5(Pool) | (7, 7) | 7 | Mean | (1, 1, 2048) | 0 / 0 | | fc1000(Output) | (2048, 1000) | None | Softmax | 1000 | 2048000 / 1000 | *==================*===============*========*============*=================*======================* |Total Number of Parameters: 25,557,096 | *=================================================================================================*
Note: 138 million parameters!!!
model2.plot_network()
new_img = ImageTable.load_files(sess,path='/dept/cas/leliuz/Data/Demo/Computer_Kerboard')
new_img.resize(224)
new_img.show()
model2.predict(data=new_img)
| Descr | Value | |
|---|---|---|
| 0 | Number of Observations Read | 1 |
| 1 | Number of Observations Used | 1 |
| 2 | Misclassification Error (%) | 100 |
| 3 | Loss Error | 0 |
| casLib | Name | Rows | Columns | casTable | |
|---|---|---|---|---|---|
| 0 | CASUSERHDFS(leliuz) | Valid_Res_fEkwmV | 1 | 1006 | CASTable('Valid_Res_fEkwmV', caslib='CASUSERHD... |
elapsed 6.94s · user 10s · sys 37.6s · mem 2.75e+04MB
model2.plot_predict_res(image_id=0,type='A')
model2.predict(data=te_img)
| Descr | Value | |
|---|---|---|
| 0 | Number of Observations Read | 81 |
| 1 | Number of Observations Used | 81 |
| 2 | Misclassification Error (%) | 100 |
| 3 | Loss Error | 0 |
| casLib | Name | Rows | Columns | casTable | |
|---|---|---|---|---|---|
| 0 | CASUSERHDFS(leliuz) | Valid_Res_Yso5Rt | 81 | 1006 | CASTable('Valid_Res_Yso5Rt', caslib='CASUSERHD... |
elapsed 5.98s · user 45.9s · sys 78s · mem 5.05e+04MB
model2.plot_predict_res(image_id=1)
model3 = VGG16(sess, model_name='VGG16',
n_classes=1000, n_channels=3, width=224, height=224, scale=1,
random_flip='none', random_crop='none',
offsets=(103.939, 116.779, 123.68),
pre_train_weight=True, include_top=True)
NOTE: Model table is attached successfully! NOTE: Model is named to "vgg16" according to the model name in the table. NOTE: Cloud Analytic Services made the uploaded file available as table LABEL_2LBZXY in caslib CASUSERHDFS(leliuz). NOTE: The table LABEL_2LBZXY has been created in caslib CASUSERHDFS(leliuz) from binary data uploaded to Cloud Analytic Services.
model3.print_summary()
*==================*===============*========*============*=================*======================* | Layer (Type) | Kernel Size | Stride | Activation | Output Size | Number of Parameters | *------------------*---------------*--------*------------*-----------------*----------------------* | data(Input) | None | None | None | (224, 224, 3) | 0 / 0 | | conv1_1(Convo.) | (3, 3) | 1 | Rectifier | (224, 224, 64) | 1728 / 64 | | conv1_2(Convo.) | (3, 3) | 1 | Rectifier | (224, 224, 64) | 36864 / 64 | | pool1(Pool) | (2, 2) | 2 | Max | (112, 112, 64) | 0 / 0 | | conv2_1(Convo.) | (3, 3) | 1 | Rectifier | (112, 112, 128) | 73728 / 128 | | conv2_2(Convo.) | (3, 3) | 1 | Rectifier | (112, 112, 128) | 147456 / 128 | | pool2(Pool) | (2, 2) | 2 | Max | (56, 56, 128) | 0 / 0 | | conv3_1(Convo.) | (3, 3) | 1 | Rectifier | (56, 56, 256) | 294912 / 256 | | conv3_2(Convo.) | (3, 3) | 1 | Rectifier | (56, 56, 256) | 589824 / 256 | | conv3_3(Convo.) | (3, 3) | 1 | Rectifier | (56, 56, 256) | 589824 / 256 | | pool3(Pool) | (2, 2) | 2 | Max | (28, 28, 256) | 0 / 0 | | conv4_1(Convo.) | (3, 3) | 1 | Rectifier | (28, 28, 512) | 1179648 / 512 | | conv4_2(Convo.) | (3, 3) | 1 | Rectifier | (28, 28, 512) | 2359296 / 512 | | conv4_3(Convo.) | (3, 3) | 1 | Rectifier | (28, 28, 512) | 2359296 / 512 | | pool4(Pool) | (2, 2) | 2 | Max | (14, 14, 512) | 0 / 0 | | conv5_1(Convo.) | (3, 3) | 1 | Rectifier | (14, 14, 512) | 2359296 / 512 | | conv5_2(Convo.) | (3, 3) | 1 | Rectifier | (14, 14, 512) | 2359296 / 512 | | conv5_3(Convo.) | (3, 3) | 1 | Rectifier | (14, 14, 512) | 2359296 / 512 | | pool5(Pool) | (2, 2) | 2 | Max | (7, 7, 512) | 0 / 0 | | fc6(F.C.) | (25088, 4096) | None | Rectifier | 4096 | 102760448 / 4096 | | fc7(F.C.) | (4096, 4096) | None | Rectifier | 4096 | 16777216 / 4096 | | fc8(Output) | (4096, 1000) | None | Softmax | 1000 | 4096000 / 1000 | *==================*===============*========*============*=================*======================* |Total Number of Parameters: 138,357,544 | *=================================================================================================*
X, y = model3.get_features(data=te_img, dense_layer='pool5')
X, y
(array([[0. , 0. , 0. , ..., 5.82558489, 0. ,
0. ],
[0. , 0. , 0. , ..., 0. , 0. ,
0. ],
[0. , 0. , 0. , ..., 0. , 0. ,
0. ],
...,
[0. , 0. , 0. , ..., 0. , 0. ,
0. ],
[0. , 0. , 0. , ..., 0. , 0. ,
0. ],
[0. , 0. , 0. , ..., 0. , 0. ,
0. ]]),
array(['Giraffe', 'Dolphin', 'Dolphin', 'Giraffe', 'Giraffe', 'Dolphin',
'Giraffe', 'Giraffe', 'Dolphin', 'Dolphin', 'Giraffe', 'Dolphin',
'Dolphin', 'Dolphin', 'Dolphin', 'Giraffe', 'Dolphin', 'Dolphin',
'Dolphin', 'Dolphin', 'Giraffe', 'Dolphin', 'Dolphin', 'Giraffe',
'Dolphin', 'Dolphin', 'Dolphin', 'Dolphin', 'Dolphin', 'Giraffe',
'Dolphin', 'Dolphin', 'Giraffe', 'Dolphin', 'Giraffe', 'Giraffe',
'Dolphin', 'Giraffe', 'Dolphin', 'Dolphin', 'Dolphin', 'Giraffe',
'Giraffe', 'Giraffe', 'Dolphin', 'Dolphin', 'Dolphin', 'Dolphin',
'Giraffe', 'Dolphin', 'Dolphin', 'Giraffe', 'Giraffe', 'Giraffe',
'Giraffe', 'Dolphin', 'Giraffe', 'Giraffe', 'Giraffe', 'Giraffe',
'Giraffe', 'Dolphin', 'Dolphin', 'Dolphin', 'Dolphin', 'Dolphin',
'Giraffe', 'Dolphin', 'Giraffe', 'Giraffe', 'Giraffe', 'Dolphin',
'Dolphin', 'Dolphin', 'Dolphin', 'Giraffe', 'Dolphin', 'Giraffe',
'Dolphin', 'Dolphin', 'Giraffe'], dtype=object))
from pipefitter.model_selection import HyperParameterTuning
from pipefitter.estimator import DecisionTree, DecisionForest, GBTree
import pandas as pd
params = dict(target='label',
inputs=[str(i) for i in range(16)])
dtree = DecisionTree(max_depth=6, **params)
data = pd.DataFrame(X)
data['label']=y
casdata = sess.upload_frame(data)
model = dtree.fit(casdata)
score = model.score(casdata)
score
NOTE: Cloud Analytic Services made the uploaded file available as table TMPKD_ROG4P in caslib CASUSERHDFS(leliuz). NOTE: The table TMPKD_ROG4P has been created in caslib CASUSERHDFS(leliuz) from binary data uploaded to Cloud Analytic Services.
NTreeNodes 5 MaxNBranches 2 NLevels 3 NLeaves 3 NBins 20 MinimumSizeofLeaves 5 MaximumSizeofLeaves 71 NVariables 16 ConfidenceLevelforPruning 0.25 NObsRead 81 NObsUsed 81 MisClassificationRate 40.7407 dtype: object
from sklearn.decomposition import PCA
import matplotlib.pyplot as plt
X_r = PCA(n_components=2).fit_transform(X)
plt.scatter(X_r[y=='Giraffe',0], X_r[y=='Giraffe',1],marker='^',c='g',label='Giraffe')
plt.scatter(X_r[y=='Dolphin',0], X_r[y=='Dolphin',1],marker='o',c='b',label='Dolphin')
plt.legend(bbox_to_anchor=(0.01, 0.99), loc=2, borderaxespad=0.)
plt.xlabel('PC1')
plt.ylabel('PC2')
plt.show()
model4 = ResNet50_Caffe(sess, model_name='ResNet50_Caffe',
n_classes=2, n_channels=3, width=224, height=224, scale=1,
random_flip='none', random_crop='none',
offsets=tr_img.channel_means,
pre_train_weight=True, include_top=False)
NOTE: Model table is attached successfully! NOTE: Model is named to "resnet50_caffe" according to the model name in the table.
model4.print_summary()
*==================*===============*========*============*=================*======================* | Layer (Type) | Kernel Size | Stride | Activation | Output Size | Number of Parameters | *------------------*---------------*--------*------------*-----------------*----------------------* | data(Input) | None | None | None | (224, 224, 3) | 0 / 0 | | conv1(Convo.) | (7, 7) | 2 | Identity | (112, 112, 64) | 9408 / 64 | | bn_conv1(B.N.) | None | None | Rectifier | (112, 112, 64) | 0 / 128 | | pool1(Pool) | (3, 3) | 2 | Max | (56, 56, 64) | 0 / 0 | | res2a_branch2a...| (1, 1) | 1 | Identity | (56, 56, 64) | 4096 / 0 | | bn2a_branch2a(...| None | None | Rectifier | (56, 56, 64) | 0 / 128 | | res2a_branch2b...| (3, 3) | 1 | Identity | (56, 56, 64) | 36864 / 0 | | bn2a_branch2b(...| None | None | Rectifier | (56, 56, 64) | 0 / 128 | | res2a_branch2c...| (1, 1) | 1 | Identity | (56, 56, 256) | 16384 / 0 | | bn2a_branch2c(...| None | None | Identity | (56, 56, 256) | 0 / 512 | | res2a_branch1(...| (1, 1) | 1 | Identity | (56, 56, 256) | 16384 / 0 | | bn2a_branch1(B...| None | None | Identity | (56, 56, 256) | 0 / 512 | | res2a(Resid.) | None | None | Rectifier | (56, 56, 256) | 0 / 0 | | res2b_branch2a...| (1, 1) | 1 | Identity | (56, 56, 64) | 16384 / 0 | | bn2b_branch2a(...| None | None | Rectifier | (56, 56, 64) | 0 / 128 | | res2b_branch2b...| (3, 3) | 1 | Identity | (56, 56, 64) | 36864 / 0 | | bn2b_branch2b(...| None | None | Rectifier | (56, 56, 64) | 0 / 128 | | res2b_branch2c...| (1, 1) | 1 | Identity | (56, 56, 256) | 16384 / 0 | | bn2b_branch2c(...| None | None | Identity | (56, 56, 256) | 0 / 512 | | res2b(Resid.) | None | None | Rectifier | (56, 56, 256) | 0 / 0 | | res2c_branch2a...| (1, 1) | 1 | Identity | (56, 56, 64) | 16384 / 0 | | bn2c_branch2a(...| None | None | Rectifier | (56, 56, 64) | 0 / 128 | | res2c_branch2b...| (3, 3) | 1 | Identity | (56, 56, 64) | 36864 / 0 | | bn2c_branch2b(...| None | None | Rectifier | (56, 56, 64) | 0 / 128 | | res2c_branch2c...| (1, 1) | 1 | Identity | (56, 56, 256) | 16384 / 0 | | bn2c_branch2c(...| None | None | Identity | (56, 56, 256) | 0 / 512 | | res2c(Resid.) | None | None | Rectifier | (56, 56, 256) | 0 / 0 | | res3a_branch2a...| (1, 1) | 2 | Identity | (28, 28, 128) | 32768 / 0 | | bn3a_branch2a(...| None | None | Rectifier | (28, 28, 128) | 0 / 256 | | res3a_branch2b...| (3, 3) | 1 | Identity | (28, 28, 128) | 147456 / 0 | | bn3a_branch2b(...| None | None | Rectifier | (28, 28, 128) | 0 / 256 | | res3a_branch2c...| (1, 1) | 1 | Identity | (28, 28, 512) | 65536 / 0 | | bn3a_branch2c(...| None | None | Identity | (28, 28, 512) | 0 / 1024 | | res3a_branch1(...| (1, 1) | 2 | Identity | (28, 28, 512) | 131072 / 0 | | bn3a_branch1(B...| None | None | Identity | (28, 28, 512) | 0 / 1024 | | res3a(Resid.) | None | None | Rectifier | (28, 28, 512) | 0 / 0 | | res3b_branch2a...| (1, 1) | 1 | Identity | (28, 28, 128) | 65536 / 0 | | bn3b_branch2a(...| None | None | Rectifier | (28, 28, 128) | 0 / 256 | | res3b_branch2b...| (3, 3) | 1 | Identity | (28, 28, 128) | 147456 / 0 | | bn3b_branch2b(...| None | None | Rectifier | (28, 28, 128) | 0 / 256 | | res3b_branch2c...| (1, 1) | 1 | Identity | (28, 28, 512) | 65536 / 0 | | bn3b_branch2c(...| None | None | Identity | (28, 28, 512) | 0 / 1024 | | res3b(Resid.) | None | None | Rectifier | (28, 28, 512) | 0 / 0 | | res3c_branch2a...| (1, 1) | 1 | Identity | (28, 28, 128) | 65536 / 0 | | bn3c_branch2a(...| None | None | Rectifier | (28, 28, 128) | 0 / 256 | | res3c_branch2b...| (3, 3) | 1 | Identity | (28, 28, 128) | 147456 / 0 | | bn3c_branch2b(...| None | None | Rectifier | (28, 28, 128) | 0 / 256 | | res3c_branch2c...| (1, 1) | 1 | Identity | (28, 28, 512) | 65536 / 0 | | bn3c_branch2c(...| None | None | Identity | (28, 28, 512) | 0 / 1024 | | res3c(Resid.) | None | None | Rectifier | (28, 28, 512) | 0 / 0 | | res3d_branch2a...| (1, 1) | 1 | Identity | (28, 28, 128) | 65536 / 0 | | bn3d_branch2a(...| None | None | Rectifier | (28, 28, 128) | 0 / 256 | | res3d_branch2b...| (3, 3) | 1 | Identity | (28, 28, 128) | 147456 / 0 | | bn3d_branch2b(...| None | None | Rectifier | (28, 28, 128) | 0 / 256 | | res3d_branch2c...| (1, 1) | 1 | Identity | (28, 28, 512) | 65536 / 0 | | bn3d_branch2c(...| None | None | Identity | (28, 28, 512) | 0 / 1024 | | res3d(Resid.) | None | None | Rectifier | (28, 28, 512) | 0 / 0 | | res4a_branch2a...| (1, 1) | 2 | Identity | (14, 14, 256) | 131072 / 0 | | bn4a_branch2a(...| None | None | Rectifier | (14, 14, 256) | 0 / 512 | | res4a_branch2b...| (3, 3) | 1 | Identity | (14, 14, 256) | 589824 / 0 | | bn4a_branch2b(...| None | None | Rectifier | (14, 14, 256) | 0 / 512 | | res4a_branch2c...| (1, 1) | 1 | Identity | (14, 14, 1024) | 262144 / 0 | | bn4a_branch2c(...| None | None | Identity | (14, 14, 1024) | 0 / 2048 | | res4a_branch1(...| (1, 1) | 2 | Identity | (14, 14, 1024) | 524288 / 0 | | bn4a_branch1(B...| None | None | Identity | (14, 14, 1024) | 0 / 2048 | | res4a(Resid.) | None | None | Rectifier | (14, 14, 1024) | 0 / 0 | | res4b_branch2a...| (1, 1) | 1 | Identity | (14, 14, 256) | 262144 / 0 | | bn4b_branch2a(...| None | None | Rectifier | (14, 14, 256) | 0 / 512 | | res4b_branch2b...| (3, 3) | 1 | Identity | (14, 14, 256) | 589824 / 0 | | bn4b_branch2b(...| None | None | Rectifier | (14, 14, 256) | 0 / 512 | | res4b_branch2c...| (1, 1) | 1 | Identity | (14, 14, 1024) | 262144 / 0 | | bn4b_branch2c(...| None | None | Identity | (14, 14, 1024) | 0 / 2048 | | res4b(Resid.) | None | None | Rectifier | (14, 14, 1024) | 0 / 0 | | res4c_branch2a...| (1, 1) | 1 | Identity | (14, 14, 256) | 262144 / 0 | | bn4c_branch2a(...| None | None | Rectifier | (14, 14, 256) | 0 / 512 | | res4c_branch2b...| (3, 3) | 1 | Identity | (14, 14, 256) | 589824 / 0 | | bn4c_branch2b(...| None | None | Rectifier | (14, 14, 256) | 0 / 512 | | res4c_branch2c...| (1, 1) | 1 | Identity | (14, 14, 1024) | 262144 / 0 | | bn4c_branch2c(...| None | None | Identity | (14, 14, 1024) | 0 / 2048 | | res4c(Resid.) | None | None | Rectifier | (14, 14, 1024) | 0 / 0 | | res4d_branch2a...| (1, 1) | 1 | Identity | (14, 14, 256) | 262144 / 0 | | bn4d_branch2a(...| None | None | Rectifier | (14, 14, 256) | 0 / 512 | | res4d_branch2b...| (3, 3) | 1 | Identity | (14, 14, 256) | 589824 / 0 | | bn4d_branch2b(...| None | None | Rectifier | (14, 14, 256) | 0 / 512 | | res4d_branch2c...| (1, 1) | 1 | Identity | (14, 14, 1024) | 262144 / 0 | | bn4d_branch2c(...| None | None | Identity | (14, 14, 1024) | 0 / 2048 | | res4d(Resid.) | None | None | Rectifier | (14, 14, 1024) | 0 / 0 | | res4e_branch2a...| (1, 1) | 1 | Identity | (14, 14, 256) | 262144 / 0 | | bn4e_branch2a(...| None | None | Rectifier | (14, 14, 256) | 0 / 512 | | res4e_branch2b...| (3, 3) | 1 | Identity | (14, 14, 256) | 589824 / 0 | | bn4e_branch2b(...| None | None | Rectifier | (14, 14, 256) | 0 / 512 | | res4e_branch2c...| (1, 1) | 1 | Identity | (14, 14, 1024) | 262144 / 0 | | bn4e_branch2c(...| None | None | Identity | (14, 14, 1024) | 0 / 2048 | | res4e(Resid.) | None | None | Rectifier | (14, 14, 1024) | 0 / 0 | | res4f_branch2a...| (1, 1) | 1 | Identity | (14, 14, 256) | 262144 / 0 | | bn4f_branch2a(...| None | None | Rectifier | (14, 14, 256) | 0 / 512 | | res4f_branch2b...| (3, 3) | 1 | Identity | (14, 14, 256) | 589824 / 0 | | bn4f_branch2b(...| None | None | Rectifier | (14, 14, 256) | 0 / 512 | | res4f_branch2c...| (1, 1) | 1 | Identity | (14, 14, 1024) | 262144 / 0 | | bn4f_branch2c(...| None | None | Identity | (14, 14, 1024) | 0 / 2048 | | res4f(Resid.) | None | None | Rectifier | (14, 14, 1024) | 0 / 0 | | res5a_branch2a...| (1, 1) | 2 | Identity | (7, 7, 512) | 524288 / 0 | | bn5a_branch2a(...| None | None | Rectifier | (7, 7, 512) | 0 / 1024 | | res5a_branch2b...| (3, 3) | 1 | Identity | (7, 7, 512) | 2359296 / 0 | | bn5a_branch2b(...| None | None | Rectifier | (7, 7, 512) | 0 / 1024 | | res5a_branch2c...| (1, 1) | 1 | Identity | (7, 7, 2048) | 1048576 / 0 | | bn5a_branch2c(...| None | None | Identity | (7, 7, 2048) | 0 / 4096 | | res5a_branch1(...| (1, 1) | 2 | Identity | (7, 7, 2048) | 2097152 / 0 | | bn5a_branch1(B...| None | None | Identity | (7, 7, 2048) | 0 / 4096 | | res5a(Resid.) | None | None | Rectifier | (7, 7, 2048) | 0 / 0 | | res5b_branch2a...| (1, 1) | 1 | Identity | (7, 7, 512) | 1048576 / 0 | | bn5b_branch2a(...| None | None | Rectifier | (7, 7, 512) | 0 / 1024 | | res5b_branch2b...| (3, 3) | 1 | Identity | (7, 7, 512) | 2359296 / 0 | | bn5b_branch2b(...| None | None | Rectifier | (7, 7, 512) | 0 / 1024 | | res5b_branch2c...| (1, 1) | 1 | Identity | (7, 7, 2048) | 1048576 / 0 | | bn5b_branch2c(...| None | None | Identity | (7, 7, 2048) | 0 / 4096 | | res5b(Resid.) | None | None | Rectifier | (7, 7, 2048) | 0 / 0 | | res5c_branch2a...| (1, 1) | 1 | Identity | (7, 7, 512) | 1048576 / 0 | | bn5c_branch2a(...| None | None | Rectifier | (7, 7, 512) | 0 / 1024 | | res5c_branch2b...| (3, 3) | 1 | Identity | (7, 7, 512) | 2359296 / 0 | | bn5c_branch2b(...| None | None | Rectifier | (7, 7, 512) | 0 / 1024 | | res5c_branch2c...| (1, 1) | 1 | Identity | (7, 7, 2048) | 1048576 / 0 | | bn5c_branch2c(...| None | None | Identity | (7, 7, 2048) | 0 / 4096 | | res5c(Resid.) | None | None | Rectifier | (7, 7, 2048) | 0 / 0 | | pool5(Pool) | (7, 7) | 7 | Mean | (1, 1, 2048) | 0 / 0 | | output(Output) | (2048, 2) | None | Softmax | 2 | 4096 / 2 | *==================*===============*========*============*=================*======================* |Total Number of Parameters: 23,512,194 | *=================================================================================================*
model4.fit(data=tr_img, mini_batch_size=1, max_epochs=3, lr=5E-3)
NOTE: Training based on existing weights. WARNING: Source layer conv1 to batch normalization layer bn_conv1 includes a bias term. NOTE: The Synchronous mode is enabled. NOTE: The total number of parameters is 23512194. NOTE: The approximate memory cost is 10082.00 MB. NOTE: Loading weights cost 1.44 (s). NOTE: Initializing each layer cost 4.76 (s). NOTE: The total number of workers is 7. NOTE: The total number of threads on each worker is 32. NOTE: The total minibatch size per thread on each worker is 1. NOTE: The maximum minibatch size across all workers for the synchronous mode is 224. NOTE: Target variable: _label_ NOTE: Number of levels for the target variable: 2 NOTE: Levels for the target variable: NOTE: Level 0: Dolphin NOTE: Level 1: Giraffe NOTE: Number of input variables: 1 NOTE: Number of numeric input variables: 1 NOTE: Batch nUsed Learning Rate Loss Fit Error Time (s) (Training) NOTE: 0 224 0.005 0.8449 0.5982 1.35 NOTE: 1 224 0.005 0.5667 0.2902 1.27 NOTE: 2 224 0.005 0.4704 0.1696 1.23 NOTE: 3 224 0.005 0.3423 0.0714 1.26 NOTE: 4 224 0.005 0.2795 0.0491 1.23 NOTE: 5 158 0.005 0.2492 0.0316 1.23 NOTE: 6 32 0.005 0.2578 0.0625 1.19 NOTE: 7 2 0.005 0.1483 0 1.24 NOTE: Epoch Learning Rate Loss Fit Error Time (s) NOTE: 0 0.005 0.464 0.2066 94.34 NOTE: Batch nUsed Learning Rate Loss Fit Error Time (s) (Training) NOTE: 0 224 0.005 0.1655 0.0045 1.28 NOTE: 1 224 0.005 0.147 0 1.27 NOTE: 2 224 0.005 0.1421 0.0179 1.22 NOTE: 3 224 0.005 0.1274 0 1.24 NOTE: 4 224 0.005 0.1064 0 1.26 NOTE: 5 158 0.005 0.1145 0 1.24 NOTE: 6 32 0.005 0.0935 0 1.26 NOTE: 7 2 0.005 0.0173 0 1.26 NOTE: 1 0.005 0.1336 0.0038 78.59 NOTE: Batch nUsed Learning Rate Loss Fit Error Time (s) (Training) NOTE: 0 224 0.005 0.0932 0 1.27 NOTE: 1 224 0.005 0.0834 0 1.25 NOTE: 2 224 0.005 0.0832 0.0089 1.25 NOTE: 3 224 0.005 0.0786 0 1.24 NOTE: 4 224 0.005 0.0659 0 1.23 NOTE: 5 158 0.005 0.0762 0 1.22 NOTE: 6 32 0.005 0.0548 0 1.24 NOTE: 7 2 0.005 0.0095 0 1.22 NOTE: 2 0.005 0.0795 0.0015 74.68 NOTE: The optimization reached the maximum number of epochs. NOTE: The total time is 247.61 (s).
| Descr | Value | |
|---|---|---|
| 0 | Model Name | resnet50_caffe |
| 1 | Model Type | Convolutional Neural Network |
| 2 | Number of Layers | 126 |
| 3 | Number of Input Layers | 1 |
| 4 | Number of Output Layers | 1 |
| 5 | Number of Convolutional Layers | 53 |
| 6 | Number of Pooling Layers | 2 |
| 7 | Number of Fully Connected Layers | 0 |
| 8 | Number of Batch Normalization Layers | 53 |
| 9 | Number of Residual Layers | 16 |
| 10 | Number of Weight Parameters | 23459008 |
| 11 | Number of Bias Parameters | 53186 |
| 12 | Total Number of Model Parameters | 23512194 |
| 13 | Approximate Memory Cost for Training (MB) | 10082 |
| Epoch | LearningRate | Loss | FitError | |
|---|---|---|---|---|
| 0 | 1 | 0.005 | 0.464024 | 0.206555 |
| 1 | 2 | 0.005 | 0.133627 | 0.003811 |
| 2 | 3 | 0.005 | 0.079538 | 0.001524 |
| casLib | Name | Rows | Columns | casTable | |
|---|---|---|---|---|---|
| 0 | CASUSERHDFS(leliuz) | resnet50_caffe_weights | 23565314 | 3 | CASTable('resnet50_caffe_weights', caslib='CAS... |
elapsed 256s · user 1.87e+04s · sys 1.47e+03s · mem 7.17e+04MB
model4.training_history
| Epoch | LearningRate | Loss | FitError | |
|---|---|---|---|---|
| 0 | 1 | 0.005 | 0.464024 | 0.206555 |
| 1 | 2 | 0.005 | 0.133627 | 0.003811 |
| 2 | 3 | 0.005 | 0.079538 | 0.001524 |
model4.plot_training_history(fig_size=(10,4))
model4.predict(data=te_img)
| Descr | Value | |
|---|---|---|
| 0 | Number of Observations Read | 81 |
| 1 | Number of Observations Used | 81 |
| 2 | Misclassification Error (%) | 0 |
| 3 | Loss Error | 0.076925 |
| casLib | Name | Rows | Columns | casTable | |
|---|---|---|---|---|---|
| 0 | CASUSERHDFS(leliuz) | Valid_Res_ltODHE | 81 | 8 | CASTable('Valid_Res_ltODHE', caslib='CASUSERHD... |
elapsed 4.73s · user 41.5s · sys 82.3s · mem 5.05e+04MB
model4.valid_conf_mat
| _label_ | Col1 | Col2 | |
|---|---|---|---|
| 0 | Dolphin | 47.0 | 0.0 |
| 1 | Giraffe | 0.0 | 34.0 |
elapsed 0.0317s · user 0.0521s · sys 0.0606s · mem 13MB
model4.plot_predict_res(type='C',image_id=2)
model4.plot_predict_res(type='A',image_id=0)
model4.heat_map_analysis(data=te_img, mask_width=56, mask_height=56, step_size=8)
NOTE : The number of images in the table is too large, only 5 randomly selected images are used in analysis. NOTE: Table IMAGEDATA_ICQFYM contains compressed images.
| _filename_0 | _image_ | _label_ | heat_map | |
|---|---|---|---|---|
| 0 | giraffe_11069.jpg | <PIL.JpegImagePlugin.JpegImageFile image mode=... | Giraffe | [[0.7036072015762329, 0.7036072015762329, 0.70... |
| 1 | dolphin_10191.jpg | <PIL.JpegImagePlugin.JpegImageFile image mode=... | Dolphin | [[0.9894927740097046, 0.9894927740097046, 0.98... |
| 2 | giraffe_10831.jpg | <PIL.JpegImagePlugin.JpegImageFile image mode=... | Giraffe | [[0.9486960768699646, 0.9486960768699646, 0.94... |
| 3 | dolphin_10937.jpg | <PIL.JpegImagePlugin.JpegImageFile image mode=... | Dolphin | [[0.9344797730445862, 0.9344797730445862, 0.93... |
| 4 | dolphin_10368.jpg | <PIL.JpegImagePlugin.JpegImageFile image mode=... | Dolphin | [[0.991266667842865, 0.991266667842865, 0.9912... |
model5 = Model(sess)
model5.load(path='/dept/cas/leliuz/Data/Demo/vgg16.sashdat')
NOTE: Model table is loaded successfully! NOTE: Model is renamed to "vgg16" according to the model name in the table. NOTE: vgg16_weights.sashdat is used as model weigths. NOTE: Model weights attached successfully! NOTE: vgg16_weights_attr.sashdat is used as weigths attribute. NOTE: Model attributes attached successfully!
model5.print_summary()
*==================*===============*========*============*=================*======================* | Layer (Type) | Kernel Size | Stride | Activation | Output Size | Number of Parameters | *------------------*---------------*--------*------------*-----------------*----------------------* | data(Input) | None | None | None | (224, 224, 3) | 0 / 0 | | conv1_1(Convo.) | (3, 3) | 1 | Rectifier | (224, 224, 64) | 1728 / 64 | | conv1_2(Convo.) | (3, 3) | 1 | Rectifier | (224, 224, 64) | 36864 / 64 | | pool1(Pool) | (2, 2) | 2 | Max | (112, 112, 64) | 0 / 0 | | conv2_1(Convo.) | (3, 3) | 1 | Rectifier | (112, 112, 128) | 73728 / 128 | | conv2_2(Convo.) | (3, 3) | 1 | Rectifier | (112, 112, 128) | 147456 / 128 | | pool2(Pool) | (2, 2) | 2 | Max | (56, 56, 128) | 0 / 0 | | conv3_1(Convo.) | (3, 3) | 1 | Rectifier | (56, 56, 256) | 294912 / 256 | | conv3_2(Convo.) | (3, 3) | 1 | Rectifier | (56, 56, 256) | 589824 / 256 | | conv3_3(Convo.) | (3, 3) | 1 | Rectifier | (56, 56, 256) | 589824 / 256 | | pool3(Pool) | (2, 2) | 2 | Max | (28, 28, 256) | 0 / 0 | | conv4_1(Convo.) | (3, 3) | 1 | Rectifier | (28, 28, 512) | 1179648 / 512 | | conv4_2(Convo.) | (3, 3) | 1 | Rectifier | (28, 28, 512) | 2359296 / 512 | | conv4_3(Convo.) | (3, 3) | 1 | Rectifier | (28, 28, 512) | 2359296 / 512 | | pool4(Pool) | (2, 2) | 2 | Max | (14, 14, 512) | 0 / 0 | | conv5_1(Convo.) | (3, 3) | 1 | Rectifier | (14, 14, 512) | 2359296 / 512 | | conv5_2(Convo.) | (3, 3) | 1 | Rectifier | (14, 14, 512) | 2359296 / 512 | | conv5_3(Convo.) | (3, 3) | 1 | Rectifier | (14, 14, 512) | 2359296 / 512 | | pool5(Pool) | (2, 2) | 2 | Max | (7, 7, 512) | 0 / 0 | | fc6(F.C.) | (25088, 4096) | None | Rectifier | 4096 | 102760448 / 4096 | | fc7(F.C.) | (4096, 4096) | None | Rectifier | 4096 | 16777216 / 4096 | | fc8(Output) | (4096, 2) | None | Softmax | 2 | 8192 / 2 | *==================*===============*========*============*=================*======================* |Total Number of Parameters: 134,268,738 | *=================================================================================================*
model5.predict(te_img)
| Descr | Value | |
|---|---|---|
| 0 | Number of Observations Read | 81 |
| 1 | Number of Observations Used | 81 |
| 2 | Misclassification Error (%) | 0 |
| 3 | Loss Error | 0.002312 |
| casLib | Name | Rows | Columns | casTable | |
|---|---|---|---|---|---|
| 0 | CASUSERHDFS(leliuz) | Valid_Res_wXRh58 | 81 | 8 | CASTable('Valid_Res_wXRh58', caslib='CASUSERHD... |
elapsed 12s · user 153s · sys 37.1s · mem 6.03e+04MB
model5.valid_conf_mat
| _label_ | Col1 | Col2 | |
|---|---|---|---|
| 0 | Dolphin | 47.0 | 0.0 |
| 1 | Giraffe | 0.0 | 34.0 |
elapsed 0.031s · user 0.0533s · sys 0.0744s · mem 13.1MB
model5.plot_predict_res(type='C',image_id=2)
model5.plot_predict_res(type='A',image_id=0)
model5.heat_map_analysis(data=te_img, mask_width=56, mask_height=56, step_size=8)
NOTE : The number of images in the table is too large, only 5 randomly selected images are used in analysis. NOTE: Table IMAGEDATA_P4UF91 contains compressed images.
| _filename_0 | _image_ | _label_ | heat_map | |
|---|---|---|---|---|
| 0 | dolphin_10442.jpg | <PIL.JpegImagePlugin.JpegImageFile image mode=... | Dolphin | [[0.9998576641082764, 0.9998576641082764, 0.99... |
| 1 | giraffe_11070.jpg | <PIL.JpegImagePlugin.JpegImageFile image mode=... | Giraffe | [[0.999992847442627, 0.999992847442627, 0.9999... |
| 2 | giraffe_10446.jpg | <PIL.JpegImagePlugin.JpegImageFile image mode=... | Giraffe | [[0.9999914169311523, 0.9999914169311523, 0.99... |
| 3 | dolphin_10368.jpg | <PIL.JpegImagePlugin.JpegImageFile image mode=... | Dolphin | [[0.9997968077659607, 0.9997968077659607, 0.99... |
| 4 | dolphin_10811.jpg | <PIL.JpegImagePlugin.JpegImageFile image mode=... | Dolphin | [[0.9928036332130432, 0.9928036332130432, 0.99... |
model5.get_feature_maps(data=te_img,label='Dolphin', image_id=0)
model5.feature_maps.display(layer_id=0)
model5.feature_maps.display(layer_id=1)
model5.feature_maps.display(layer_id=2)
model5.feature_maps.display(layer_id=18)
NOTE: The maximum number of filters to be displayed is 64. NOTE: Only the first 64 filters are displayed.
sess.endsession()
elapsed 0.00747s · user 0.00235s · sys 0.0115s · mem 1.63MB